/*
 * TODO
 */
package com.xtrip.net.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.xtrip.common.BasicConstant;
import com.xtrip.common.BusinessConstant;
import com.xtrip.common.CtripConstant;
import com.xtrip.common.ElongConstant;
import com.xtrip.common.TcConstant;

/**
 * @project xtrip
 * @author shiming.yao
 * @time 2013-4-3
 */
public class RequestSend {

	private String qryType = null;
	private int provider = -1;
	private Map params = null;
	private String requestUrl = null;
	private String content = null;

	/**
	 * 
	 */
	public RequestSend(String requestUrl ,String qryType, int provider, Map params) {
		this.qryType = qryType;
		this.params = params;
		this.provider = provider;
		this.requestUrl = requestUrl;
	}
	public RequestSend(String requestUrl ,String qryType, int provider, String content) {
		this.qryType = qryType;
		this.content = content;
		this.provider = provider;
		this.requestUrl = requestUrl;
	}

	public String post() {
		if (qryType.equals(BusinessConstant.TYPE_PLANE))
			return postPlane();
		else if (qryType.equals(BusinessConstant.TYPE_HOTEL))
			return postHotel();
		return null;
	}

	private String postPlane() {
		return null;
	}

	private String postHotel() {
		String result = null;
		switch (provider) {
		case 1:
			result = sendToElong();
			break;
		case 2:
			result = sendToCtrip();
			break;
		case 3:
			result = sendTo17U();
			break;
		case 4:
			result = sendToZhuna();
			break;
		}
		return result;
	}

	private String sendToElong() {
		String result = HttpRequestMethod.sendWebservice(content,
				requestUrl, "paraName", BasicConstant.ENCODE_UTF8,
				ElongConstant.HOST, ElongConstant.SOAPAction,BusinessConstant.PROVIDER_HOTEL_ELONG);
		//provider
		return result;
	}

	private String sendToCtrip() {
		String result = HttpRequestMethod.sendWebservice(content,
				requestUrl, "paraName", BasicConstant.ENCODE_UTF8,
				CtripConstant.HOST, CtripConstant.SOAPAction,BusinessConstant.PROVIDER_HOTEL_CTRIP);
		//provider
		return result;
	}

	private String sendTo17U() {
		String result = HttpRequestMethod.sendHttpPost(requestUrl, content, BasicConstant.ENCODE_UTF8);
		return result;
	}

	private String sendToZhuna() {
		StringBuffer sb = new StringBuffer("?");
		Set keyset = params.keySet();
		Iterator<String> it = keyset.iterator();
		while (it.hasNext()) {
			String key = it.next();
			sb.append(key + "=" + params.get(key) + "&");
		}
		String result = HttpRequestMethod.sendHttpPost(
				requestUrl + sb.toString(), "",
				BasicConstant.ENCODE_UTF8);
		return result;
	}

}
